package quotation.utils;


public class PassWdCheckUtil {
    public static final String PW_PATTERN = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[_\\W])[a-zA-Z0-9_\\W]{8,}$";

    public static boolean checkIfWeakPassWd(String passWd) {
        char[] chars = passWd.toCharArray();
        boolean flag = false;
        char  alpha;
        for (int i = 1; i < chars.length-1; i++) {
            alpha =chars[i];
            if (('a' < alpha && alpha < 'z') || ('A' < alpha && alpha < 'Z') || ('0' < alpha && alpha < '9')) {
                if ((int)chars[i]-1 == (int)chars[i - 1] &&(int)chars[i]+1 == (int)chars[i + 1]) {
                    flag = true;
                    break;
                }
                if ((int)chars[i] == (int)chars[i - 1] &&(int)chars[i] == (int)chars[i + 1]) {
                    flag = true;
                    break;
                }
            }
        }
        boolean matches = !passWd.matches(PW_PATTERN);
        return flag || matches;
    }


    public static void main(String[] args) {
        String pw1 = "ABCDEFGHIG";
        String pw2 = "abcdefghig";
        String pw3 = "0123456789";
        String pw4 = "!@#$%^&*()";
        String pw5 = "ABCDEabcde";
        String pw6 = "ABCDE01234";
        String pw7 = "ABCDE!@#$%";
        String pw8 = "abcde01234";
        String pw9 = "abcde!@#$%";
        String pw10 = "01234!@#$%";
        String pw11 = "abcde01234!@#$%";
        String pw12 = "ABCDE01234!@#$%";
        String pw13 = "ABCDEabcde!@#$%";
        String pw14 = "ABCDEabcde01234";
        String pw15 = "Aa0!";
        String pw16="ABCabc012!@#";
        String pw17="ABab01!@#";
        String pw18="abAB01!@#";
        String pw19="1!@#abAB0";

        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw1));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw2));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw3));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw4));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw5));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw6));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw7));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw8));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw9));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw10));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw11));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw12));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw13));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw14));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw15));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd(pw16));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd((pw17)));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd((pw18)));
        System.out.println(PassWdCheckUtil.checkIfWeakPassWd((pw19)));

    }
}
